using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;   
namespace QUANLYBANHANG
{
    class KETNOIDULIEU
    {
        OleDbConnection con;
        public KETNOIDULIEU()
        {
            con = new OleDbConnection();
            //con.ConnectionString = "provider=sqlNCLI.1; "
            //+ " data source=localhost;"
            //+ " initial catalog=quanlybanhang;"
            //+ " integrated security=SSPI";

            con.ConnectionString="provider=Microsoft.Jet.Oledb.4.0;Data source= "
             + System.Windows.Forms.Application.StartupPath 
             + "\\quanlybanhang.mdb"; 
                
                }

        public void MoKetNoi()
        {
            if (con.State == ConnectionState.Closed)
                con.Open(); 
        }
        public void DongKetNoi()
        {
            if (con.State == ConnectionState.Open)
                con.Close(); 
        }
        public DataTable Bang(string SQL)
        {
            DataTable tb = new DataTable(); 
            OleDbDataAdapter adp = new OleDbDataAdapter(SQL, con);
            adp.Fill(tb);
            return tb;
        }
        public DataSet TapDuLieu(string SQL)
        {
            DataSet ds = new DataSet();
            ds.Tables.Add(Bang(SQL));
            return ds;
        }
        public void CapnhatDulieu(string SQL, ref DataSet ds)
        {
            OleDbDataAdapter adp = new OleDbDataAdapter(SQL, con);
            OleDbCommandBuilder cdb = new OleDbCommandBuilder(adp);
            adp.Update(ds); 
        }
        public void ThucThiSQL(string SQL)
        {
            OleDbCommand cmd = new OleDbCommand(SQL, con);
            cmd.ExecuteNonQuery(); 
        }

    }
}
